|
|
|
|
|
|
|
you convert these classes into a component, the function will not be accessible to those using the object. In an ideal world, you would be able to specify that only the ServiceManager class could call the Initialize method, but in Visual Basic, using a Friend function is the best we can do. Because the classes are incorporated directly into the utility in this example, the use of a Friend attribute is no different than using a Public attribute, since Friend allows the function to be visible to the entire project. However, Friend is used here in case you decide to place the class in a component and to emphasize to the programmer that access to the function should be limited. The OpenService method is shown here: |
|
|
|
|
|
|
|
|
' Open a service and return the service object
Public Function OpenService(Svc As ServiceStatus, rights As _
ServiceAccessRights) As ServiceObject
Dim hnd&
Dim newservice As New ServiceObject
' Service manager must be open to perform this operation
If schandle = 0 Then Exit Function
hnd = intOpenService(schandle, Svc.Name, rights Or SERVICE_QUERY_STATUS)
If hnd <> 0 Then
' Initialize the service via a Friend function
Call newservice.Initialize(hnd, Svc.Name, Svc.DisplayName)
Set OpenService = newservice
End If
End Function |
|
|
|
|
|
|
|
|
The EnumServicesStatus function is the trickiest one of the lot. The lpServices parameter described earlier takes a pointer to a memory buffer to load with a bunch of ENUM_SERVICES_STATUS structures. Let's take a quick look at this structure and how it will be defined in Visual Basic. The C declarations are as follows: |
|
|
|
|
|
|
|
|
typedef struct _ENUM_SERVICE_STATUS { // ess
LPTSTR lpServiceName;
LPTSTR lpDisplayName;
SERVICE_STATUS ServiceStatus;
} ENUM_SERVICE_STATUS, *LPENUM_SERVICE_STATUS;
typedef struct _SERVICE_STATUS { // ss
DWORD dwServiceType;
DWORD dwCurrentState;
DWORD dwControlsAccepted;
DWORD dwWin32ExitCode; |
|
|
|
|
|